package com.example.hdx.controller;


import com.example.hdx.DOT.loginrDTO;
import com.example.hdx.entity.User;
import com.example.hdx.mapper.UserMapper;
import com.example.hdx.service.UserService;
import com.example.hdx.util.FwResult;
import com.example.hdx.util.JwtUtil;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.hdx.DOT.loginDTO;


@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    UserMapper userMapper;

//    @PostMapping("/login")
//    public FwResult<User> login(
//            @RequestParam String username,
//            @RequestParam String password,
//            HttpSession session) {
//        FwResult<User> result = userService.login(username, password);
//        if (result.isSuccess() && result.getData() != null) {
//            User user = result.getData();
//            // 将用户ID存入Session
//            session.setAttribute("userId", user.getId());
////            System.out.println("当前登录用户ID：" + user.getId());
//        }
//
////        return userService.login(username, password);
//
//        return result;
//    }

        @PostMapping("/login")
        public FwResult<loginrDTO> login(@RequestBody  loginDTO DTO) {
            return userService.login(DTO.getUsername(), DTO.getPassword());
        }






    @PostMapping("/register")
    public FwResult<Void> register(@RequestBody User user) {
        return userService.register(user);
    }
}